<?php

class PropertyFactory implements Factory
{
	protected $_index = 'class';
	
	public function __construct($index = 'class')
    {
		if (!is_string($index) || empty($index)) {
            throw new InvalidArgumentException('Invalid index name given');
		}
		$this->_index = $index;
	}
	
	public function __toString()
	{
	    return get_class($this);
	}
	
	public function create(array $data)
	{
		if (!isset($data[$this->_index])) {
			throw new FactoryException('Couldn\'t find the index in data');
		}
		return $this->_create($data, $data[$this->_index]);
	}
	
	protected function _create(array $data, $class)
	{
	    return new $class($data);
	}
}